﻿using System;

namespace ES.Client
{
    public static class StringExt
    {
        public static int? ToInt32(this string s)
        {
            if (string.IsNullOrWhiteSpace(s))
            {
                return null;
            }

            int v = 0;
            if (int.TryParse(s, out v))
            {
                return v;
            }

            return null;
        }

        public static double? ToDouble(this string s)
        {
            if (string.IsNullOrWhiteSpace(s))
            {
                return null;
            }

            double v = 0d;
            if (double.TryParse(s, out v))
            {
                return v;
            }

            return null;
        }

        public static DateTime? ToDateTime(this string s)
        {
            if (string.IsNullOrWhiteSpace(s))
            {
                return null;
            }

            DateTime v = DateTime.MinValue;
            if (DateTime.TryParse(s, out v))
            {
                return v;
            }

            return null;
        }
    }
}
